<template>
    <div>
        <van-nav-bar id="reset" :title="hisFlag == 0 ? '加号记录' : '亲情就诊记录'" left-arrow @click-left="backHandle" fixed
            z-index="100" />


        <div class="pageCon fuPage">

            <div class="listBox">
                <div class="listTop">
                    <span>
                        筛选
                    </span>
                    <div>
                        <span></span>
                        <van-popover v-model="showPopover" placement="bottom-end" trigger="click" theme="dark"
                            :actions="statusList" @select="onSelect">
                            <template #reference>
                                <template v-if="selectStatus == -1">全部</template>
                                <template v-if="selectStatus == 0">审核人审核中</template>
                                <template v-if="selectStatus == 1">已通过</template>
                                <template v-if="selectStatus == 2">医助已驳回</template>
                                <template v-if="selectStatus == 3">医助审核中</template>
                                <template v-if="selectStatus == 4">审核人已驳回</template>
                                <van-icon name="bars" />
                            </template>
                        </van-popover>
                    </div>
                </div>

                <div class="listMain">
                    <template v-if="historyList.length != 0">
                        <div class="itemBox" v-for="(item, index) in historyList" :key="index">
                            <div class="orderNumTip">
                                申请编号：{{ item.orderNumber }}
                            </div>
                            <div>
                                <span>就诊人：{{ item.userName || '暂无' }}</span>
                                <span v-if="item.orderStatus == 0">
                                    审核人审核中
                                </span>
                                <span v-if="item.orderStatus == 1" class="passColor">
                                    已审核
                                </span>
                                <span v-if="item.orderStatus == 2" class="resColor">
                                    医助已驳回
                                </span>
                                <span v-if="item.orderStatus == 3">
                                    医助审核中
                                </span>
                                <span v-if="item.orderStatus == 4" class="resColor">
                                    审核人已驳回
                                </span>
                            </div>
                            <div>
                                <span v-if="hisFlag == 0">医生：{{ item.doctorName || '暂无' }}</span>
                                <span>申请时间：{{ item.createTime }}</span>
                            </div>

                            <div class="imgBox" v-if="hisFlag == 1 && item.imgList.length != 0">
                                <span>相关图片</span>
                                <div>
                                    <img :src="ele.imgUrl" alt="" v-for="(ele, eIndex) in item.imgList" :key="eIndex"
                                        @click="checkImg(item.imgList, eIndex)">
                                </div>
                            </div>
                            <div class="passRea" v-if="item.orderStatus == 2 || item.orderStatus == 4">
                                驳回原因： {{ item.unPass }}
                            </div>
                            <div class="passRea" v-if="item.orderStatus == 1"> <span>就诊时间：{{ item.visitTime
                                    }}</span>
                            </div>
                            <div class="btnBox" v-if="item.orderStatus == 2">
                                <div class="applyBtn" @click="resHandle(item)">重新提交</div>
                            </div>

                        </div>
                    </template>
                    <div class="emptyBox" v-else>
                        <img src="../../assets/tip_content.png">
                    </div>

                </div>
            </div>
        </div>







    </div>

</template>

<script>
import { ImagePreview } from 'vant';
import { getUserOrderDetail, unApplyService } from '../../network/family'
export default {
    name: 'HomeR',
    data() {
        return {
            isLoading: false,

            hisFlag: 0, //  1  亲情就诊  0 加号记录


            historyList: [],
            oldList: [],

            user: JSON.parse(localStorage.user),

            selectStatus: -1,
            showPopover: false,
            statusList: [
                {
                    text: '默认分类',
                    value: -1
                },
                {
                    text: '审核人审核中',
                    value: 0
                },
                {
                    text: '已通过',
                    value: 1
                },
                {
                    text: '医助已驳回',
                    value: 2
                },
                {
                    text: '医助审核中',
                    value: 3
                },
                {
                    text: '审核人已驳回',
                    value: 4
                },
            ],

        }
    },
    mounted() {

    },
    methods: {
        onSelect(action) {
            console.log(action);
            this.selectStatus = action.value
            this.historyList = this.oldList.filter(item => {
                if (this.selectStatus == -1) {
                    return item
                } else {
                    return item.orderStatus == this.selectStatus
                }
            })

        },
        resHandle(obj) {

            this.selectObj = obj


        },

        backHandle() {
            this.$router.back()
        },
        pullHandle() {

            this.isLoading = true
            this.getList()
        },

        getList() {

            getUserOrderDetail({
                userId: localStorage.userId,
                parentCode: this.user.parentCode,
            }).then(res => {
                if (res.flag) {
                    this.isLoading = false
                    this.historyList = res.data.filter(item => {
                        return item.orderType == this.hisFlag
                    })
                    this.historyList.reverse()
                    this.oldList = JSON.parse(JSON.stringify(this.historyList))
                }
            })

        },


        checkImg(list, index) {

            console.log(list);
            var arr = []
            list.forEach(item => {
                arr.push(item.imgUrl)
            })
            console.log(arr);
            ImagePreview({
                images: arr, // 需要预览的图片 URL 数组
                showIndex: true, // 是否显示页码
                closeable: true, // 是否显示关闭图标	
                startPosition: index,
                showIndicators: true
            })
        },


    },
    created() {

        console.log(this.$router);
        console.log(this.$router.history.current.query);
        this.hisFlag = this.$router.history.current.query.flag
        this.getList()
    },
    //计算属性
    computed: {

    },
    filters: {

    },
    watch: {
    }

}

</script>

<style lang='less' scoped>
.pageCon {

    padding: 112px 20px 0 !important;
    box-sizing: border-box;
    position: relative;
    width: 100%;
    height: 100vh;
    background-color: #EEF1F7;
    overflow: hidden;
}


.listBox {
    width: 100%;
    height: 100%;
    // background: #fff;
    border-radius: 20px;
    box-shadow: 0px 2px 6px 0px rgba(51, 51, 51, 0.08);
    overflow-y: scroll;
}


.listTop {
    position: sticky;
    top: 0px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    padding: 30px 34px 10px 44px;
    width: 100%;
    font-family: Source Han Sans CN;
    font-weight: 500;
    font-size: 28px;
    color: #333333;
    background: #fff;
    border-radius: 20px;
}

.listTop>div>span:nth-child(2) {
    margin-left: 30px;
    color: #999999;
}

.itemBox {
    margin-bottom: 20px;
    box-sizing: border-box;
    padding: 44px 30px 44px 44px;
    width: 100%;
    background: #fff;
    box-shadow: 0px 2px 6px 0px rgba(51, 51, 51, 0.08);
    border-radius: 20px;
    border-bottom: 2px solid #f2f2f2;
}

.itemBox>div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    font-family: Source Han Sans CN;
    font-weight: 400;
    font-size: 28px;
    color: #333333;
    line-height: 38px;

}

.itemBox>div:nth-child(3) {
    margin-top: 12px;
}

.itemBox>div:nth-child(3)>span:last-child {
    font-size: 24px;
    color: #999999;
}

#reset /deep/ .van-nav-bar__left .van-nav-bar__text,
#reset /deep/ .van-nav-bar__left .van-icon {
    color: #333 !important;
}

.emptyBox {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.emptyBox>img {
    margin-top: 400px;
    width: 374px;
    height: 314px;
}

.applyRes {
    margin-top: 12px;
    justify-content: start !important;
    font-size: 24px !important;
    color: #666 !important;
}

.applyRes>span {
    color: #333 !important;
}


.passRea {
    padding-top: 24px;
    border-top: 1px solid #f2f2f2;
    font-size: 28px !important;
    color: #999 !important;
}

.btnBox {
    margin-top: 24px;
    display: flex;
    align-items: center !important;
    justify-content: flex-end !important;

    width: 100%;
}

.imgBox {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start !important;
    padding-top: 24px;
    border-top: 1px solid #f2f2f2;
    width: 100%;
}

.imgBox>span {
    font-size: 28px;
    color: #999;
}

.imgBox>div>img {
    margin: 16px 16px 16px 0;
    width: 100px;
    height: 100px;
    // background: aqua;
    border-radius: 16px;
}


.resColor {
    color: #F56C6C !important;
}

.passColor {
    color: #67C23A !important;
}

.applyBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 136px;
    height: 48px;
    border-radius: 24px;
    border: 1px solid rgba(27, 178, 106, .5);
    font-family: Source Han Sans CN;
    font-weight: bold;
    font-size: 20px;
    color: #1BB26A !important;
}

.orderNumTip {
    margin-bottom: 12px;
    width: 100%;
    font-size: 24px;
    color: #333;
}
</style>